﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Doo.DataView;
using Doo.WebUI;

namespace Doo.Controls
{
    [ParseChildren(true)]
    public class TreeView : DataView.DataViewBase, Doo.Scripts.IClientEvent<TreeView.TreeViewClientEvents>
    {
        const string _ScriptName = "Doo.WebUI.DataView.TreeView.script.js";

        #region 基础属性
        public override string ClientControlType
        {
            get
            {
                return "Doo.TreeView";
            }
        }

        public override string ScriptResourceName
        {
            get
            {
                return _ScriptName;
            }
        }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        protected override string TagName
        {
            get
            {
                return "div";
            }
        }
        #endregion

        #region 客户端事件

        public class TreeViewClientEvents : DataViewClientEvents
        {
        }

        [PersistenceMode(PersistenceMode.InnerProperty)]
        public TreeViewClientEvents ClientEvents { get; set; }

        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (this.TemplateEvents != null) this.TemplateEvents.Init(Page, Parent);
            if (this.ClientEvents != null) this.ClientEvents.Init(Page, Parent);
        }

        private string _cssclass;
        public override string CssClass
        {
            get
            {
                return _cssclass;
            }
            set
            {
                _cssclass = value;
            }
        }

        protected override void SetScriptDescriptor(ScriptControlDescriptor descriptor)
        {
            base.SetScriptDescriptor(descriptor);

            if (this.TemplateEvents != null && this.TemplateEvents.Count > 0)
            {
                descriptor.AddProperty("tplevents", this.TemplateEvents.ToHashtable());
            }

            if (!string.IsNullOrEmpty(_cssclass))
            {
                descriptor.AddProperty("css", _cssclass);
            }

        }

    }
}
